﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for ManagementProduct
/// </summary>
public class ManagementProduct
{
    SqlConnection conn;
	public ManagementProduct()
	{
		//
		// TODO: Add constructor logic here
		//
        conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
	}

    public DataSet GetVendor()
    {
        string query = "SELECT * FROM Vendors";
        SqlDataAdapter da = new SqlDataAdapter(query,conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        return ds;
    }

    public DataSet GetProductType()
    {
        string query = "SELECT * FROM ProductType";
        SqlDataAdapter da = new SqlDataAdapter(query, conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        return ds;
    }

    public DataSet GetProduct()
    {
        string query = "SELECT Product.ProductID,Product.ProductName,Product.Description,UrlImg,Price,Quantity,VendorName,TypeName FROM Product "
                        +"JOIN Vendors "
                        +"ON Product.VendorID = Vendors.VendorID "
                        +"JOIN ProductType "
                        +"ON Product.ProductTypeID = ProductType.ProductTypeID";
        SqlDataAdapter da = new SqlDataAdapter(query, conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        return ds;
    }

    public object GetProductByVendorID(int p)
    {
        string query = "SELECT Product.ProductID,Product.ProductName,Product.Description,UrlImg,Price,Quantity,VendorName,TypeName FROM Product "
                        + "JOIN Vendors "
                        + "ON Product.VendorID = Vendors.VendorID "
                        + "JOIN ProductType "
                        + "ON Product.ProductTypeID = ProductType.ProductTypeID WHERE Product.VendorID="+p;
        SqlDataAdapter da = new SqlDataAdapter(query, conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        return ds;
    }

    public object GetProductByProductTypeID(int p)
    {
        string query = "SELECT Product.ProductID,Product.ProductName,Product.Description,UrlImg,Price,Quantity,VendorName,TypeName FROM Product "
                        + "JOIN Vendors "
                        + "ON Product.VendorID = Vendors.VendorID "
                        + "JOIN ProductType "
                        + "ON Product.ProductTypeID = ProductType.ProductTypeID WHERE Product.ProductTypeID=" + p;
        SqlDataAdapter da = new SqlDataAdapter(query, conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        return ds;
    }
}